import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // vueJsx(),
    VueSetupExtend(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': resolve('packages'),
    },
    extensions: ['.ts']
  },
  // 打包配置
  build: {
    // target: 'modules',
    outDir: 'lib', // 输出路径
    assetsDir: 'assets', // 静态资源存放路径
    minify: 'terser', // 混淆
    lib: {
      entry: resolve(__dirname, 'packages/index.ts'),
      name: 'vo-element',
      fileName: (format) => `index.${format}.js`,
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ['vue'],
      output: {
        // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
        globals: {
          vue: 'Vue',
        },
      },
    },
  },
  // 本地运行配置
  server: {
    cors: true, // 默认启用并允许任何源
    open: true, // 自动打开浏览器
    port: 5111,
  },
  
  
})
